package com.yc.vote.service.impl;

import com.yc.common.biz.BizException;
import com.yc.vote.entity.Record;
import com.yc.vote.mapper.RecordMapper;
import com.yc.vote.service.IRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.vote.util.MyBatisHelper;
import com.yc.vote.util.Utils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyl
 * @since 2022-11-06
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements IRecordService {

    public void commit(List<Record> records) throws BizException {
        Utils.check(records == null || records.isEmpty(),"请选择投票选项");
        MyBatisHelper.exec(session -> {
            records.forEach(record -> {
                session.getMapper(RecordMapper.class).insert(record);
            });
        });
    }
}
